package org.openems.entity;

import java.util.ArrayList;
import java.util.List;


public class ChoiceEntity extends AbstractEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8695606502506998713L;
	
	private List<String> choices = new ArrayList<String>();
	private Integer index = 0;
	
	@Override
	public boolean equals(Object obj) {
		ChoiceEntity newObj = (ChoiceEntity)obj;
		return this.index.equals(newObj.index);
	}
	@Override
	protected ChoiceEntity clone() {
		try {
			ChoiceEntity ret = (ChoiceEntity)super.clone();
			ret.setChoices(new ArrayList<String>(choices));
			return ret;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public ChoiceEntity(Key key, String name, boolean persisted) {
		super(key, name, persisted);
	}
	public ChoiceEntity(Key key, String name, List<String> choice, boolean persisted) {
		super(key, name, persisted);
		this.setChoices(choice);
		
	}
	public List<String> getChoices() {
		return choices;
	}
	public void setChoices(List<String> choices) {
		this.choices = choices;
	}
	public Integer getIndex() {
		return index;
	}
	public void setIndex(Integer index) {
		this.index = index;
	}

	@Override
	public String getValueText() {
		return this.getChoices().get(this.index);
	}
	@Override
	public void setValueText(String text) {
		if (this.getChoices().contains(text)) {
			this.index = this.getChoices().indexOf(text);
		}
	}
	@Override
	public Entity getClone() {
		return clone();
	}

}
